package com.company.algo.niuke;

import java.util.LinkedList;
import java.util.Stack;

public class BigDataAdd {
    /**
     “大”数，需要按位进行相加，思路与AddTwoNumbers一致
     */
    public String solve (String s, String t) {
        Stack<Integer> stack1 = new Stack<>();
        Stack<Integer> stack2 = new Stack<>();
        for(int i=0;i<s.length();i++) stack1.push(Character.getNumericValue(s.charAt(i)));
        for(int i=0;i<t.length();i++) stack2.push(Character.getNumericValue(t.charAt(i)));
        int carry = 0;
        LinkedList<String> res = new LinkedList<>();
        while(!stack1.isEmpty() || !stack2.isEmpty() || carry!=0){
            int sum = carry;
            if(!stack1.isEmpty()) sum += stack1.pop();
            if(!stack2.isEmpty()) sum += stack2.pop();
            carry = sum/10;
            res.addFirst(String.valueOf(sum%10));
        }
        StringBuilder sb = new StringBuilder();
        res.forEach(sb::append);
        return sb.toString();
    }
}
